from mpython import *
import network
import urequests
import json
import time

my_wifi = wifi()

my_wifi.connectWiFi("CMCC-GoodMaker", "steam666")


num = 0
if my_wifi.sta.isconnected():
    oled.fill(0)
    oled.DispChar("连接成功", 0, 0, 1)
    oled.DispChar((str(my_wifi.sta.ifconfig()[0])), 0, 16, 1)
    oled.show()
else:
    oled.fill(0)
    oled.DispChar("连接失败", 0, 0, 1)
    oled.show()
while True:
    _response = urequests.post("http://192.168.1.6/post-esp-data.php/", headers={"Content-Type":"application/json"}, data=json.dumps({"api_key":"tPmAT5Ab3j7F9", "sensor":"Light", "location":"Office", "value1":str(light.read()), "value2":str(sound.read()), "value3":"3", "id":str(num + 1)}))
    print(_response.text)
    time.sleep(3)
